<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{$Think.config.site.title} - 客户余额变动</title>
    <meta name="keywords" content="{$Think.config.site.keywords}">
    <meta name="description" content="{$Think.config.site.description}">
    <link href="{$Think.config.site.resource_url}css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/animate.css" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/plugins/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/style.css?v=4.1.0" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/plugins/datapicker/datepicker3.css" rel="stylesheet">
</head>
<style type="text/css">
    .yue{ display: inline-block; width:120px; text-align: center; }
    .float-e-margins .fuhao{ margin-bottom:0px; background-color: #F7F7F7; border: 1px solid #F7F7F7; color: #333;}
    .float-e-margins .fuhao:active{background-color: #F7F7F7;border: 1px solid #F7F7F7;color: #333;}
</style>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <form method="post" class="form-horizontal" action="" id="myform" >
                        <input type="hidden" name="id" value="{$v['id'] ?? ''}" />
                        <div class="form-group">
                            <label class="col-sm-2 control-label">{:lang('用户名')}</label>
                            <div class="col-sm-10">
                                <input id="" name="" class="form-control" type="text" value="{$v['name'] ?? ''}" disabled="true">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">{:lang('当前余额')}</label>
                            <div class="col-sm-10">
                                <input id="dangqianjine" name="" class="form-control" type="text" value="{$v['balance'] ?? ''}" readOnly="true" disabled="true">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">{:lang('选择类型')}*</label>
                            <div class="col-sm-10">
                                <div class="radio radio-info radio-inline">
                                    <input type="radio" id="plus" value="1" name="fh" >
                                    <label for="plus"> ╋ </label>
                                </div>
                                <div class="radio radio-info radio-inline">
                                    <input type="radio" id="minus" value="2" name="fh">
                                    <label for="minus"> ━ </label>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">{:lang('更改余额')}</label>
                            <div class="col-sm-10">
                                <!-- <a  class="btn btn-primary fuhao" id="plus">加</a> --><input id="balance" name="yue" class="form-control yue" type="text" placeholder="{:lang('请谨慎操作')}!" ><!-- <a  class="btn btn-primary fuhao" id="minus">减</a> -->　{:lang('结果')}：<span id="change" style="color:red;"></span>{:lang('元')}
                            </div>
                            <input type="hidden" name="fuhao" value="" id="fuhao">
                            <input type="hidden" name="zz" value="" id='zz'>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-2">
                                <input type="button" class="btn btn-primary" value="{:lang('提交')}" id="onbtn">
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="{$Think.config.site.resource_url}js/jquery.min.js?v=2.1.4"></script>
<script src="{$Think.config.site.resource_url}js/bootstrap.min.js?v=3.3.5"></script>
<script src="{$Think.config.site.resource_url}js/content.min.js?v=1.0.0"></script>
<script src="{$Think.config.site.resource_url}js/plugins/iCheck/icheck.min.js"></script>
<script src="{$Think.config.site.resource_url}js/plugins/datapicker/bootstrap-datepicker.js"></script>
<script src="{$Think.config.site.resource_url}js/plugins/validate/jquery.validate.min.js"></script>
<script src="{$Think.config.site.resource_url}js/plugins/validate/messages_zh.min.js"></script>
<script src="{$Think.config.site.resource_url}js/plugins/layer/layer.js"></script>
<script src="{$Think.config.site.resource_url}js/plugins/sweetalert/sweetalert.min.js"></script>
<script type="text/javascript">
    var re = /^[+-]?\d*\.?\d{0,2}$/;

    $(function(){
        $('#plus').click(function(){
            var val = $('#balance').val();
            if (!re.test(val)){
                $('#balance').focus();
                $('#balance').val('');
                layer.msg("{:lang('请输入数字')}", {icon: 5});
                return false;
            }
            if(val==''){
                $('#balance').focus();
                $('#balance').val('');
                layer.msg("{:lang('请输入数字')}", {icon: 5});
                return false;
            }
            var balance = $('#dangqianjine').val();
            var cbalance = $('#balance').val();
            var end = (Number(balance) + Number(cbalance)).toFixed(2);
            $('#change').html("{:lang('加了后余额变为：')}"+end);
            $('#zz').val(end);
            $('#fuhao').val('+');
        });
        $('#minus').click(function(){
            var val = $('#balance').val();
            if (!re.test(val)){
                $('#balance').focus();
                $('#balance').val('');
                layer.msg("{:lang('请输入数字')}", {icon: 5});
                return false;
            }
            if(val==''){
                $('#balance').focus();
                $('#balance').val('');
                layer.msg("{:lang('请输入数字')}", {icon: 5});
                return false;
            }
            var balance = $('#dangqianjine').val();
            var cbalance = $('#balance').val();
            var end = (Number(balance) - Number(cbalance)).toFixed(2);
            $('#change').html("{:lang('减了后余额变为：')}"+end);
            $('#zz').val(end);
            $('#fuhao').val('-');
        });

        $('#onbtn').click(function(){
            var fomrData = $("#myform").serialize();
            var balance = $('#balance').val();
            var fuhao = $('#fuhao').val();
            if(fuhao ==''){
                layer.msg("{:lang('请选择+金额还是-金额')}", {icon: 5});
                return false;
            }
            if(balance ==''){
                $('#balance').focus();
                layer.msg("{:lang('请正确输入金额')}", {icon: 5});
                return false;
            }

            layer.confirm("{:lang('确定要更改金额？')}", {
                    btn: ["{:lang('确定')}","{:lang('取消')}"], //按钮
                    shade: false //不显示遮罩
                }, function(){
                    //确定删除
                    $.ajax({
                        type: "post",
                        url : '<?php echo \think\Request::instance()->root(); ?>/<?php echo \think\Request::instance()->module(); ?>/Orders/change',
                        dataType : 'json',
                        data : fomrData,
                        success: function(result){
                            if(0 === result.code) {
                                layer.msg(result.msg, {icon: 1});
                                parent.location.reload();
                            }else{
                                layer.msg(result.msg, {icon: 5});
                            }
                        },
                        error : function(){
                            layer.msg("{:lang('服务器错误！请稍后重试')}", {icon: 2});
                        }
                    });
                },
                function(){

                });
        });
    });
</script>
</body>
</html>